var mallHome = {
	init: function(){
		mallHome.header();
		mallHome.searchBox();
        mallHome.picTab();
	},

	header: function(){
        $('.msn').mouseenter(function(){
            $(this).addClass('hover');
        }).mouseleave(function(){
            $(this).removeClass('hover');
        })

        $('.shopCar').mouseenter(function(){
            $(this).addClass('hover');
        }).mouseleave(function(){
            $(this).removeClass('hover');
        })

		$('#btn_login').click(function(){
			$(this).hide().parent().find('span').html('<a href="">您好，周杰伦</a>');
			$('#btn_register').hide();
			$('#btn_quit').show();
		})
		$('#btn_quit').click(function(){
			$(this).hide().parent().find('span').html('喵，欢迎来找钢！');
			$('#btn_register').show();
			$('#btn_login').show();
		})
	},

    //主搜索框切换
	searchBox: function(){
		$('.search_nav a').mouseenter(function(){
			var $btn_li = $(this).parent();
			$btn_li.addClass('cur').siblings().removeClass('cur');
			var num = $btn_li.index();
			$('.search_main_box').eq(num).show().siblings().hide();
            mallHome.hideError('.index_search_box input');
            if(num !== 1){
                $('.lo_city').hide();
                $('.lo_goods').hide();
            }
		})	
	},

    //胖猫物流，客服人数统计
    countNum: function(num){
        for (var i = 0; i<num.length; i++) {
            var q = num.substring(i,i+1);
            var _val = '<i>'+q+'</i>';
            $('#logistics_customVal').append(_val);
        };
    },

    //幻灯片
    picTab: function(){
        if($('.main_banner_slides .slides_container').find('div').length>1){
            $('.main_banner_slides .slides_container').slidesjs({
                height: 320,
                navigation: {
                    active:false
                },
                play: {
                    active: false,
                    auto: true,
                    interval: 3000,
                    swap: true,
                    pauseOnHover: true,
                    restartDelay: 3000
                }
            });
        }
        if($('.process .slides_container').find('div').length>1){
            $('.process .slides_container').slidesjs({
                width: 940,
                height: 320,
                navigation: {
                    active:false
                },
                play: {
                    active: false,
                    auto: true,
                    interval: 3000,
                    swap: true,
                    pauseOnHover: true,
                    restartDelay: 3000
                }
            });
        }
        if($('.logistics .slides_container').find('div').length>1){
            $('.logistics .slides_container').slidesjs({
                width: 940,
                height: 320,
                navigation: {
                    active:false
                },
                play: {
                    active: false,
                    auto: true,
                    interval: 3000,
                    swap: true,
                    pauseOnHover: true,
                    restartDelay: 3000
                }
            });
        }

        //滚动按钮切换hover显示
        $('.slides_trends, .slides_order, .company_list_box,.prixbar_slide').mouseenter(function(){
            $(this).addClass('on');
        }).mouseleave(function(){
            $(this).removeClass('on');
        })

        //调价动态
        if($('.slides_trends').find('ul').length>1){
            $('.slides_trends').slidesjs({
                width: 900,
                height: 466,
                pagination: {
                    active: false
                },
                play: {
                    active: false,
                    auto: false,
                    interval: 6000,
                    swap: true,
                    pauseOnHover: true,
                    restartDelay: 6000
                }
            });
        }

        if($('.prixbar_slide').find('ul').length>1){
            $('.prixbar_slide').slidesjs({
                width:240,
                height:220,
                pagination: {
                    active: false
                },
                play: {
                    active: false,
                    auto: false,
                    interval: 6000,
                    swap: true,
                    pauseOnHover: true,
                    restartDelay: 6000
                }
            });
        }

        //钢厂logo滚动
        if($('.company_list_box').find('ul').length>1){
            $('.company_list_box').slidesjs({
                width: 1180,
                height: 122,
                pagination: {
                    active: false
                },
                play: {
                    active: false,
                    auto: true,
                    interval: 6000,
                    swap: true,
                    pauseOnHover: true,
                    restartDelay: 6000
                }
            });
        }


        //求购
        if($('.slides_order').find('ul').length>1){
            $('.slides_order').slidesjs({
                width: 620,
                height: 182,
                pagination: {
                    active: false
                },
                play: {
                    active: false,
                    auto: true,
                    interval: 6000,
                    swap: true,
                    pauseOnHover: true,
                    restartDelay: 6000
                }
            });
        }
    },

    //显示报错
    showError: function(domTarget,Msg){
        $(domTarget).parent().addClass('error').find('.errorMsg').html(Msg);
    },

    //隐藏报错
    hideError: function(domTarget){
        $(domTarget).parent().removeClass('error').find('.errorMsg').html('');
    }    
}

$(function(){
	mallHome.init();
    mallHome.countNum("12318");

    if(!!navigator.userAgent.match(/AppleWebKit.*Mobile.*/)){
        $('body, .slidesjs-container, .slidesjs-control').width('1180');
    }

    //折线图
    $('#chart1').highcharts({
        title: {
            text: '热卷价格走势',
            align: 'left',
            verticalAlign: 'top',
            style: {
  				fontWeight: 'bold',
  				fontSize: '14px'
  			}
        },
        chart:{
            marginTop:35
        },
        credits: {
            enabled: false
        },
        subtitle: {
            text: '普卷5.75*1500*C',
            align: 'right',
            verticalAlign: 'top',
            y: 10,
            x: -6,
            style: {
                color: '#333'
            }
        },
        xAxis: {
            categories: ['07/16', '07/16', '07/16', '07/16', '07/16'],
            gridLineWidth: 1,
            lineColor: '#b4b4b4',
            tickColor: '#b4b4b4',
            labels: {
                style: {
                    color: '#333',
                    font: '11px Trebuchet MS, Verdana, sans-serif'
                }
            },
            title: {
                style: {
                    color: '#333',
                    fontWeight: 'bold',
                    fontSize: '12px',
                    fontFamily: 'Trebuchet MS, Verdana, sans-serif'

                }
            }
        },
        yAxis: {
            minorTickInterval: 'auto',
            lineColor: '#b4b4b4',
            lineWidth: 1,
            tickWidth: 1,
            tickColor: '#b4b4b4',
            labels: {
                style: {
                    color: '#444',
                    font: '11px Trebuchet MS, Verdana, sans-serif'
                }
            },
            title: {
                text: null,
                style: {
                    color: '#333',
                    fontWeight: 'bold',
                    fontSize: '12px',
                    fontFamily: 'Trebuchet MS, Verdana, sans-serif'
                }
            }
        },
        navigation: {
            buttonOptions: {
                theme: {
                    stroke: '#CCCCCC'
                }
            }
        },
        legend: {
            enabled: false,
            align: 'right',
            verticalAlign: 'top',
            y: -8,
            borderWidth: 0,
            itemStyle: {
				        font: '9pt Trebuchet MS, Verdana, sans-serif',
                color: 'black'
			      },
            itemHoverStyle: {
                color: '#039'
            },
            itemHiddenStyle: {
                color: 'gray'
            }
        },
        labels: {
            style: {
                color: '#99b'
            }
        },
        tooltip: {
            style:{
                color: '#333',
                fontSize: '10px',
                padding: '4px'
            }
        },
        colors: ['#2c85de'],
        series: [{
            name: '热卷',
            data: [82, 108, 50, 73, 66]
        }]
    });

    $('#chart2').highcharts({
        title: {
            text: '热卷价格走势',
            align: 'left',
            verticalAlign: 'top',
            style: {
          fontWeight: 'bold',
          fontSize: '14px'
        }
        },
        chart:{
            marginTop:35
        },
        credits: {
            enabled: false
        },
        subtitle: {
            text: '普卷5.75*1500*C',
            align: 'right',
            verticalAlign: 'top',
            y: 10,
            x: -6,
            style: {
                color: '#333'
            }
        },
        xAxis: {
            categories: ['07/16', '07/16', '07/16', '07/16', '07/16'],
            gridLineWidth: 1,
            lineColor: '#b4b4b4',
            tickColor: '#b4b4b4',
            labels: {
                style: {
                    color: '#333',
                    font: '11px Trebuchet MS, Verdana, sans-serif'
                }
            },
            title: {
                style: {
                    color: '#333',
                    fontWeight: 'bold',
                    fontSize: '12px',
                    fontFamily: 'Trebuchet MS, Verdana, sans-serif'

                }
            }
        },
        yAxis: {
            minorTickInterval: 'auto',
            lineColor: '#b4b4b4',
            lineWidth: 1,
            tickWidth: 1,
            tickColor: '#b4b4b4',
            labels: {
                style: {
                    color: '#444',
                    font: '11px Trebuchet MS, Verdana, sans-serif'
                }
            },
            title: {
                text: null,
                style: {
                    color: '#333',
                    fontWeight: 'bold',
                    fontSize: '12px',
                    fontFamily: 'Trebuchet MS, Verdana, sans-serif'
                }
            }
        },
        navigation: {
            buttonOptions: {
                theme: {
                    stroke: '#CCCCCC'
                }
            }
        },
        legend: {
            enabled: false,
            align: 'right',
            verticalAlign: 'top',
            y: -8,
            borderWidth: 0,
            itemStyle: {
                font: '9pt Trebuchet MS, Verdana, sans-serif',
                color: 'black'
            },
            itemHoverStyle: {
                color: '#039'
            },
            itemHiddenStyle: {
                color: 'gray'
            }
        },
        labels: {
            style: {
                color: '#99b'
            }
        },
        tooltip: {
            style:{
                color: '#333',
                fontSize: '10px',
                padding: '4px'
            }
        },
        colors: ['#2c85de'],
        series: [{
            name: '热卷',
            data: [82, 108, 50, 73, 66]
        }]
    });
    $('#chart3').highcharts({
        title: {
            text: '热卷价格走势',
            align: 'left',
            verticalAlign: 'top',
            style: {
          fontWeight: 'bold',
          fontSize: '14px'
        }
        },
        chart:{
            marginTop:35
        },
        credits: {
            enabled: false
        },
        subtitle: {
            text: '普卷5.75*1500*C',
            align: 'right',
            verticalAlign: 'top',
            y: 10,
            x: -6,
            style: {
                color: '#333'
            }
        },
        xAxis: {
            categories: ['07/16', '07/16', '07/16', '07/16', '07/16'],
            gridLineWidth: 1,
            lineColor: '#b4b4b4',
            tickColor: '#b4b4b4',
            labels: {
                style: {
                    color: '#333',
                    font: '11px Trebuchet MS, Verdana, sans-serif'
                }
            },
            title: {
                style: {
                    color: '#333',
                    fontWeight: 'bold',
                    fontSize: '12px',
                    fontFamily: 'Trebuchet MS, Verdana, sans-serif'

                }
            }
        },
        yAxis: {
            minorTickInterval: 'auto',
            lineColor: '#b4b4b4',
            lineWidth: 1,
            tickWidth: 1,
            tickColor: '#b4b4b4',
            labels: {
                style: {
                    color: '#444',
                    font: '11px Trebuchet MS, Verdana, sans-serif'
                }
            },
            title: {
                text: null,
                style: {
                    color: '#333',
                    fontWeight: 'bold',
                    fontSize: '12px',
                    fontFamily: 'Trebuchet MS, Verdana, sans-serif'
                }
            }
        },
        navigation: {
            buttonOptions: {
                theme: {
                    stroke: '#CCCCCC'
                }
            }
        },
        legend: {
            enabled: false,
            align: 'right',
            verticalAlign: 'top',
            y: -8,
            borderWidth: 0,
            itemStyle: {
                font: '9pt Trebuchet MS, Verdana, sans-serif',
                color: 'black'
            },
            itemHoverStyle: {
                color: '#039'
            },
            itemHiddenStyle: {
                color: 'gray'
            }
        },
        labels: {
            style: {
                color: '#99b'
            }
        },
        tooltip: {
            style:{
                color: '#333',
                fontSize: '10px',
                padding: '4px'
            }
        },
        colors: ['#2c85de'],
        series: [{
            name: '热卷',
            data: [82, 108, 50, 73, 66]
        }]
    });
    $('#chart4').highcharts({
        title: {
            text: '热卷价格走势',
            align: 'left',
            verticalAlign: 'top',
            style: {
          fontWeight: 'bold',
          fontSize: '14px'
        }
        },
        chart:{
            marginTop:35
        },
        credits: {
            enabled: false
        },
        subtitle: {
            text: '普卷5.75*1500*C',
            align: 'right',
            verticalAlign: 'top',
            y: 10,
            x: -6,
            style: {
                color: '#333'
            }
        },
        xAxis: {
            categories: ['07/16', '07/16', '07/16', '07/16', '07/16'],
            gridLineWidth: 1,
            lineColor: '#b4b4b4',
            tickColor: '#b4b4b4',
            labels: {
                style: {
                    color: '#333',
                    font: '11px Trebuchet MS, Verdana, sans-serif'
                }
            },
            title: {
                style: {
                    color: '#333',
                    fontWeight: 'bold',
                    fontSize: '12px',
                    fontFamily: 'Trebuchet MS, Verdana, sans-serif'

                }
            }
        },
        yAxis: {
            minorTickInterval: 'auto',
            lineColor: '#b4b4b4',
            lineWidth: 1,
            tickWidth: 1,
            tickColor: '#b4b4b4',
            labels: {
                style: {
                    color: '#444',
                    font: '11px Trebuchet MS, Verdana, sans-serif'
                }
            },
            title: {
                text: null,
                style: {
                    color: '#333',
                    fontWeight: 'bold',
                    fontSize: '12px',
                    fontFamily: 'Trebuchet MS, Verdana, sans-serif'
                }
            }
        },
        navigation: {
            buttonOptions: {
                theme: {
                    stroke: '#CCCCCC'
                }
            }
        },
        legend: {
            enabled: false,
            align: 'right',
            verticalAlign: 'top',
            y: -8,
            borderWidth: 0,
            itemStyle: {
                font: '9pt Trebuchet MS, Verdana, sans-serif',
                color: 'black'
            },
            itemHoverStyle: {
                color: '#039'
            },
            itemHiddenStyle: {
                color: 'gray'
            }
        },
        labels: {
            style: {
                color: '#99b'
            }
        },
        tooltip: {
            style:{
                color: '#333',
                fontSize: '10px',
                padding: '4px'
            }
        },
        colors: ['#2c85de'],
        series: [{
            name: '热卷',
            data: [82, 108, 50, 73, 66]
        }]
    });


    $('#btn_submit_xh').click(function(){
        var _val = $('#xh_company').val();
        if(_val==""){
            mallHome.showError("#xh_company","请选择");
        }
    });
    $('#btn_submit_jg').click(function(){
        var _val = $('#jg_address').val();
        if(_val==""){
            mallHome.showError("#jg_address","请填写");
        }
    });
    $('#btn_submit_price').click(function(){
        var _val = $('#wlType').val();
        if(_val==""){
            mallHome.showError("#wlType","请填写货物");
        }
    });
    

    $('input').focusin(function(){
        mallHome.hideError(this);
    })

    $("#wlStart, #wlEnd").on("click",function(){
        var top = $(this).offset().top+42;
        var left = $(this).offset().left;
        $(".lo_city").show().css({"top":top,"left":left});
        $('.lo_goods').hide();
    });
    $(".lo_city").on("click",".list a,.close,.listbox a",function(){
        $(".lo_city").hide();
    });


    $("#wlType").on("click",function(){
        var top = $(this).offset().top+42;
        var left = $(this).offset().left;
        $(".lo_goods").show().css({"top":top,"left":left});
        $('.lo_city').hide();
    });
    $(".lo_goods").on("click",".close",function(){
        $(".lo_goods").hide();
    });
    $(".lo_goods").on("click",".list a",function(){
        var _val = $(this).text();
        $("#wlType").val(_val);
        $(".lo_goods").hide();
    });


    //找现货地区
    $("#xh_area").Address({
        source: {
            alias: ['pinyin', 'cityName', 'cityId'],
            suggestion: {
                '热门城市': [
                    { display: '北京', data: 'Beijing|北京|2' },
                    { display: '上海', data: 'Shanghai|上海|4' },
                    { display: '南京', data: 'Nanjing|南京|6' },
                    { display: '厦门', data: 'Xiamen|厦门|8' }
                ],
                '常用城市': [{ display: '天津', data: 'Tianjin|天津|3' }]
            },
            data: "@Beijing|北京|2@Shanghai|上海|4@Nanjing|南京|6@Xiamen|厦门|8@Tianjin|天津|3@"
        },
        template: {
            filterPageSize: 3
        },
        isAutoCorrect:true
    });

    //找现货仓库
    $("#storehouse").Address({
        source: {
            suggestion:{
                '华东': {
                     data:[{
                         display:"上海市",
                         data:[
                             {display:"中船库",data:"ZhongChuanKu|中船库|3"},
                             {display:"填进仓库",data:"TianJinKu|填进仓库|4"},
                             {display:"611仓库",data:"611CangKu|611仓库|5"},
                             {display:"全案超市",data:"QuanAnChaoShi|全案超市|6"},
                             {display:"中船库",data:"ZhongChuanKu|中船库|3"},
                             {display:"填进仓库",data:"TianJinKu|填进仓库|4"},
                             {display:"611仓库",data:"611CangKu|611仓库|5"},
                             {display:"全案超市",data:"QuanAnChaoShi|全案超市|6"},
                             {display:"中船库",data:"ZhongChuanKu|中船库|3"},
                             {display:"填进仓库",data:"TianJinKu|填进仓库|4"},
                             {display:"611仓库",data:"611CangKu|611仓库|5"},
                             {display:"全案超市",data:"QuanAnChaoShi|全案超市|6"},
                             {display:"中船库",data:"ZhongChuanKu|中船库|3"},
                             {display:"填进仓库",data:"TianJinKu|填进仓库|4"},
                             {display:"611仓库",data:"611CangKu|611仓库|5"},
                             {display:"全案超市",data:"QuanAnChaoShi|全案超市|6"}
                         ]
                     },
                     {
                         display:"无锡市",
                         data:[
                             {display:"中船库",data:"ZhongChuanKu|中船库|3"},
                             {display:"填进仓库",data:"TianJinKu|填进仓库|4"},
                             {display:"611仓库",data:"611CangKu|611仓库|5"},
                             {display:"全案超市",data:"QuanAnChaoShi|全案超市|6"}
                         ]
                     }
                     ]
                },
                '华北': {
                     data:[{
                         display:"上海市11",
                         data:[
                             {display:"中船库1",data:"ZhongChuanKu|中船库|3"},
                             {display:"填进仓库1",data:"TianJinKu|填进仓库|4"},
                             {display:"611仓库1",data:"611CangKu|611仓库|5"},
                             {display:"全案超市1",data:"QuanAnChaoShi|全案超市|6"}
                         ]
                     }]
                }           
            }
        },
        template: {
            suggestion:'\
                    <div class="c_address_box" id="depotAddress" style="display:none;">\
                        <i></i>\
                        <div class="c_address_hd"><$= GlobalData.message $></div>\
                        <div class="c_address_bd">\
                            <ol class="c_address_ol">\
                                <$ for(var key in GlobalData.data){ $>\
                                    <li><span><$= key $></span></li>\
                                <$ } $>\
                            </ol>\
                           <$ for(var key in GlobalData.data){  $>\
                            <ul class="c_address_ul layoutfix">\
                                <$ for(var kk in GlobalData.data[key]){ $>\
                                    <$ var item = GlobalData.data[key][kk]; $>\
                                    <$ for(var k=0,kl=item.length; k<kl;k++){ $>\
                                        <$ var it =item[k]; var isLast=(k===kl-1);$>\
                                        <$ if(isLast){ $>\
                                           <li class="last"><span><$= it.display $></span><div class="c_ul_box">\
                                       <$ } else{$>\
                                            <li><span><$= it.display $></span><div class="c_ul_box">\
                                       <$ } $>\
                                        <$ for(var j=0,jl=it.data.length;j<jl;j++){ $>\
                                            <$ var iit = it.data[j];$>\
                                            <a data="<$= iit.data $>" href="javascript:void(0);"><$= iit.display $></a>\
                                        <$ } $>\
                                        </div></li>\
                                    <$ } $>\
                                <$ } $>\
                            </ul>\
                            <$ } $>\
                        </div>\
                    </div>\
                ',
        suggestionInit:function(pObj){
                var _spans=pObj.find(".c_address_ol").find('span'),
                    _uls=pObj.find('ul');
                if (!_spans.length){
                    return;
                }
                function switchTab(){
                    var _this=this;
                    _spans.each(function(i,span){
                        if (span==_this){
                            $(span).addClass('hot_selected');
                            _uls[i].style.display='';
                        }else{
                            $(span).removeClass('hot_selected');
                            _uls[i].style.display='none';
                        }
                    });
                }
                var w=30;
                for (var i=0,n=_spans.length;i<n;i++){
                    w+=_spans[i].offsetWidth;
                }
                var t=pObj.find('div').first();
                if (t[0]){
                    if (w>278){
                        t.css('width',w+'px');
                    }
                }
                _spans.bind('mousedown',switchTab);
                switchTab.apply(_spans[0]);
            }
        },
        isAutoCorrect:true
    });

    // //品名
    // $("#type_name").Address({
    //     source: {
    //         data: "@Dihejinjuan|低合金卷|1@Pujuan|普卷|2@Cliao|C料|3@Huawenjuan|花纹卷|4@"
    //     },
    //     template: {
    //         filterPageSize: 3
    //     }
    // });

    // //规格
    // $("#specifications").Address({
    //     source: {
    //         data: "@|15.75*1500*C|1@|16.75*2000*C|2@"
    //     },
    //     template: {
    //         filterPageSize: 3
    //     }
    // });

    // //材质
    // $("#quality").Address({
    //     source: {
    //         data: "@|CDC03|1@|Q235B|2@|Q235B|3@|Q235B|4@|Q235B|5@"
    //     },
    //     template: {
    //         filterPageSize: 3
    //     }
    // });


    //找钢厂
    $("#xh_company").Address({
        source: {
            alias: ['pinyin', 'companyName', 'companyId'],
            suggestion: {
                '热门': [
                    { display: '新抚顺', data: 'Xinfushun|新抚顺|0' },
                    { display: '凌钢', data: 'Linggang|凌钢|1' }
                ],
                '历史选择': [{ display: '本钢', data: 'Bengang|本钢|2' }]
            },
            data: "@Xinfushun|新抚顺|0@Shanghai|凌钢|4@Nanjing|Linggang|1@Xiamen|厦门|8@Bengang|本钢|2@"
        },
        template: {
            filterPageSize: 3
        },
        isAutoCorrect:true
    });

    $('.slides_trends a, .slides_order a').addClass('active');

    $('.search_button').click(function(){
        var _val = $('#findGoods').val();
        if(_val==""){
            var popup = new UIpopup({
                width:600,
                height:300,
                template: '<div class="box"><i class="pass"></i><div class="main"><h2>需求已发送</h2><p>请填写采购需求！</p><a href="javascript:void(0)" class="btns btn_enter">确定</a></div></div>'
            });
        }
    })
    $('body').on('click','.btn_enter', function(){
        $(".popup .close").trigger("click")
    })

    var gotop = new goTop();
})

